package com.web.config;

import com.jfinal.config.*;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.web.controller.*;
import com.web.model.CardLaunchRecord;
import com.web.model.Message;
import com.web.model.Records;
import com.web.model.UserModel;

/**
 * Created by reeves on 2015/7/3.
 */
public class JfinalConfig extends JFinalConfig {
    @Override
    public void configConstant(Constants me) {
        me.setDevMode(true); //设置开发者模式为开
    }

    @Override
    public void configRoute(Routes me) {
        me.add("/route", RouteController.class);
        me.add("/launchcard", CardController.class);
        me.add("/user", UserController.class);
        me.add("/record", RecordController.class);
        me.add("/wechat", WechatSignatureController.class);
        me.add("/share", ShareController.class);
        me.add("/upload", UploadImgController.class);
        me.add("/message",MessageController.class);
    }

    @Override
    public void configPlugin(Plugins me) {
        /**
         * 使用 C3P0 连接池管理数据库连接
         */

        //TODO:数据库使用的是RDS2，做测试用
        C3p0Plugin c3p0Plugin = new C3p0Plugin("jdbc:mysql://rm-uf6po11tq87945gavo.mysql.rds.aliyuncs.com:3306/kuibusoftware", "kbapp_admin", "Kuibureeves52155");
        me.add(c3p0Plugin);
        /**
         * 使用 ActiveRecord 操作数据库
         */
        ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(c3p0Plugin);
        me.add(activeRecordPlugin);

        activeRecordPlugin.addMapping("v1_grass_user", "id", UserModel.class);
        activeRecordPlugin.addMapping("v1_grass_launchcard", "id", CardLaunchRecord.class);
        activeRecordPlugin.addMapping("v1_grass_record", "id", Records.class);
        activeRecordPlugin.addMapping("v1_grass_message","id", Message.class);

    }

    @Override
    public void configInterceptor(Interceptors me) {

    }

    @Override
    public void configHandler(Handlers me) {
    }
}
